var e = require("../../@babel/runtime/helpers/interopRequireDefault"), t = e(require("../../@babel/runtime/regenerator")), a = require("../../@babel/runtime/helpers/asyncToGenerator"), r = e(require("../../http/address")), n = require("../../utils/area"), d = e(require("../../miniprogram_npm/@vant/weapp/toast/toast")), i = require("../../utils/tool"), s = new r.default(), u = getApp();

Page({
    data: {
        areaFlag: !1,
        deleteFlag: !1,
        saveFlag: !1,
        areaList: n.areaList,
        addressId: "",
        memberName: "",
        defaultStatus: 0,
        phone: "",
        province: "",
        city: "",
        region: "",
        detailAddress: "",
        provinceCode: 0,
        cityCode: 0,
        regionCode: 0,
        count: 0,
        isDelete: !0,
        title: "添加收货地址"
    },
    onLoad: function(e) {
        this.setData({
            count: e.count
        });
        var t = e.addressid;
        t && (this.getAddressDetails(t), this.setData({
            title: "编辑收货地址"
        }));
    },
    onShow: function() {
        this.ifHideDelete();
    },
    getMemberName: function(e) {
        this.setData({
            memberName: e.detail.value
        });
    },
    getPhone: function(e) {
        this.setData({
            phone: e.detail.value
        });
    },
    getAetailAddress: function(e) {
        this.setData({
            detailAddress: e.detail.value
        });
    },
    ifHideDelete: function() {
        var e = getCurrentPages();
        "pages/order_pick/order_pick" == e[e.length - 1].route && this.setData({
            isDelete: !1
        });
    },
    areaFlagChange: function(e) {
        this.setData({
            areaFlag: !this.data.areaFlag
        });
    },
    areaConfirm: function(e) {
        console.log(e);
        var t = e.detail.values;
        this.setData({
            province: t[0].name,
            city: t[1].name,
            region: t[2].name,
            provinceCode: t[0].code,
            cityCode: t[1].code,
            regionCode: t[2].code
        }), this.areaFlagChange();
    },
    deleteFlagChange: function() {
        1 != this.data.count ? 1 != this.data.defaultStatus ? this.selectComponent("#clear-dialog").show() : (0, 
        d.default)("默认地址不可删除") : (0, d.default)("至少保留一个地址");
    },
    onChange: function(e) {
        var t = e.detail;
        this.setData({
            defaultStatus: t
        });
    },
    saveAddress: function() {
        var e = this;
        return a(t.default.mark(function a() {
            var r, n;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    if (r = /[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF][\u200D|\uFE0F]|[\uD83C|\uD83D|\uD83E][\uDC00-\uDFFF]|[0-9|*|#]\uFE0F\u20E3|[0-9|#]\u20E3|[\u203C-\u3299]\uFE0F\u200D|[\u203C-\u3299]\uFE0F|[\u2122-\u2B55]|\u303D|[\A9|\AE]\u3030|\uA9|\uAE|\u3030/gi, 
                    !(e.data.memberName.match(r) || e.data.phone.match(r) || e.data.detailAddress.match(r))) {
                        t.next = 4;
                        break;
                    }
                    return (0, d.default)("输入框不允许输入emoji表情"), t.abrupt("return");

                  case 4:
                    if (e.data.memberName) {
                        t.next = 7;
                        break;
                    }
                    return (0, d.default)("请输入收货人"), t.abrupt("return");

                  case 7:
                    if (e.data.phone) {
                        t.next = 10;
                        break;
                    }
                    return (0, d.default)("请输入手机号"), t.abrupt("return");

                  case 10:
                    if ((0, i.checkMobile)(e.data.phone)) {
                        t.next = 13;
                        break;
                    }
                    return (0, d.default)("手机号请输入11位数字！"), t.abrupt("return");

                  case 13:
                    if (e.data.province) {
                        t.next = 16;
                        break;
                    }
                    return (0, d.default)("请选择所在地区"), t.abrupt("return");

                  case 16:
                    if (e.data.detailAddress) {
                        t.next = 19;
                        break;
                    }
                    return (0, d.default)("请输入详细地址"), t.abrupt("return");

                  case 19:
                    return n = {
                        addressId: e.data.addressId,
                        memberName: e.data.memberName,
                        defaultStatus: e.data.defaultStatus,
                        phone: e.data.phone,
                        province: e.data.province,
                        city: e.data.city,
                        region: e.data.region,
                        detailAddress: e.data.detailAddress,
                        provinceCode: e.data.provinceCode,
                        cityCode: e.data.cityCode,
                        regionCode: e.data.regionCode
                    }, t.prev = 20, u.showLoading(), t.next = 24, s.editAddress(n);

                  case 24:
                    t.sent, (0, i.toastThen)("更新成功"), t.next = 30;
                    break;

                  case 28:
                    t.prev = 28, t.t0 = t.catch(20);

                  case 30:
                    return t.prev = 30, wx.hideLoading(), t.finish(30);

                  case 33:
                  case "end":
                    return t.stop();
                }
            }, a, null, [ [ 20, 28, 30, 33 ] ]);
        }))();
    },
    getAddressDetails: function(e) {
        var r = this;
        return a(t.default.mark(function a() {
            var n, d;
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.next = 2, s.addressDetails(e);

                  case 2:
                    n = t.sent, d = n.data, r.setData({
                        addressId: d.addressId,
                        memberName: d.memberName,
                        defaultStatus: d.defaultStatus,
                        phone: d.phone,
                        province: d.province,
                        city: d.city,
                        region: d.region,
                        detailAddress: d.detailAddress,
                        provinceCode: d.provinceCode,
                        cityCode: d.cityCode,
                        regionCode: d.regionCode
                    });

                  case 5:
                  case "end":
                    return t.stop();
                }
            }, a);
        }))();
    },
    deleteAddress: function() {
        var e = this;
        return a(t.default.mark(function a() {
            return t.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    return t.prev = 0, u.showLoading(), t.next = 4, s.deleteAddress(e.data.addressId);

                  case 4:
                    e.selectComponent("#clear-dialog").onClose(), (0, i.toastThen)("删除成功"), t.next = 10;
                    break;

                  case 8:
                    t.prev = 8, t.t0 = t.catch(0);

                  case 10:
                    return t.prev = 10, wx.hideLoading(), t.finish(10);

                  case 13:
                  case "end":
                    return t.stop();
                }
            }, a, null, [ [ 0, 8, 10, 13 ] ]);
        }))();
    },
    turnBack: function() {
        u.returnUI();
    }
});